﻿//------------------------------------------------------------------------------
//Author: Christoph van der Fecht
//CodePlex: http://www.codeplex.com/site/users/view/ChristophvdF
//
//Copyright(c) Christoph van der Fecht
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace SerienNewsReader.Model
{
    public class RSSFeed : INotifyPropertyChanged, IComparable
    {
        /// <summary>
        /// Indicates that a poroperty changed its value.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// private member, containing the title of the serie
        /// </summary>
        private String title = default(String);

        /// <summary>
        /// the private member containing the language of the serie
        /// </summary>
        private String language = default(String);

        /// <summary>
        /// private member containing the link of the feed
        /// </summary>
        private Uri link = default(Uri);

        /// <summary>
        /// Eventhandler when a property was changed
        /// </summary>
        /// <param name="propertyName">the name of the property that changes his value.</param>
        protected virtual void OnPropertyChange(String propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        /// <summary>
        /// Creats a new RSSFeed object
        /// </summary>
        /// <param name="title">the title of the serie</param>
        /// <param name="language">the language of the serie</param>
        /// <param name="link">the link to the serie</param>
        public RSSFeed(String title, String language, Uri link)
        {
            this.Title = title;
            this.Language = language;
            this.Link = link;
        }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            RSSFeed feed = null;
            if (obj is RSSFeed)
                feed = obj as RSSFeed;
            else
                return 0;
            if (feed != null)
                return feed.Title.CompareTo(this.Title);
            else
                return 0;
        }

        #endregion

        /// <summary>
        /// The title of the serie
        /// </summary>
        public String Title
        {
            get
            {
                return this.title;
            }

            set
            {
                this.title = value;
                OnPropertyChange("Title");
            }
        }

        /// <summary>
        /// The language of the serie
        /// </summary>
        public String Language
        {
            get { return this.language; }
            set
            {
                this.language = value;
                OnPropertyChange("Language");
            }
        }

        /// <summary>
        /// The link for the feed
        /// </summary>
        public Uri Link
        {
            get { return this.link; }
            set
            {
                this.link = value;
                OnPropertyChange("Link");
            }
        }
    }
}
